#############################################################
#
# Driver for wifistix module
#
#############################################################
CF8385_VERSION:=5.0.16.p0-26306
CF8385_SOURCE:=cf8385-$(CF8385_VERSION).tbz
CF8385_SITE:=http://files.gumstix.com
CF8385_DIR:=$(BUILD_DIR)/src_cf8385
CF8385_CAT:=bzcat
CF8385_MODULE=$(CF8385_DIR)/mcf25.ko
CF8385_TARGET_MODULE=$(TARGET_DIR)/lib/modules/.cf8385

CF8385_TARGET_CONF=$(BUILD_DIR)/.cf8385

$(DL_DIR)/$(CF8385_SOURCE):
	 $(WGET) -P $(DL_DIR) $(CF8385_SITE)/$(CF8385_SOURCE)

cf8385-source: $(DL_DIR)/$(CF8385_SOURCE)

$(CF8385_DIR)/.unpacked: $(DL_DIR)/$(CF8385_SOURCE)
	$(CF8385_CAT) $(DL_DIR)/$(CF8385_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	touch $(CF8385_DIR)/.unpacked

$(CF8385_DIR)/.patched: $(CF8385_DIR)/.unpacked
	(cd $(CF8385_DIR); QUILT_PATCHES=$(BASE_DIR)/package/wifistix $(QUILT) push -a)
	echo $(BASE_DIR)/package/wifistix > $@

$(CF8385_MODULE): $(BASE_DIR)/uImage $(CF8385_DIR)/.patched
	(cd $(CF8385_DIR); \
	$(MAKE) CONFIG_GUMSTIX=y CONFIG_DEBUG=n KVER=2.6 KERNELDIR="$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(ARCH) CC="$(TARGET_CC)" EXTRA_CFLAGS="$(TARGET_CFLAGS)";)

$(CF8385_TARGET_CONF): $(CF8385_MODULE)
	(cd $(CF8385_DIR); \
	$(MAKE) CONFIG_GUMSTIX=y CONFIG_DEBUG=n KVER=2.6 KERNELDIR="$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(ARCH) CC="$(TARGET_CC)" EXTRA_CFLAGS="$(TARGET_CFLAGS)" INSTALL_MOD_PATH="$(TARGET_DIR)" install;)
	(grep -q mcf25 $(TARGET_DIR)/etc/modprobe.conf || \
	 echo -e 'alias mwlan0 mcf25\ninstall cfio /sbin/modprobe proc-gpio && echo GPIO out set > /proc/gpio/GPIO80 && /sbin/pccardctl eject && /sbin/modprobe --ignore-install cfio && /sbin/pccardctl insert' >> $(TARGET_DIR)/etc/modprobe.conf)
	(grep -q mwlan0 $(TARGET_DIR)/etc/network/interfaces || \
	 echo -e '\nauto mwlan0\niface mwlan0 inet dhcp\n	pre-up /sbin/iwconfig $$IFACE essid any txpower 100mW\n' >> $(TARGET_DIR)/etc/network/interfaces)
	touch $@

wifistix: $(CF8385_TARGET_CONF)

wifistix-clean:
	@echo Nothing to do to clean wifistix -- must be cleaned manually
	-$(MAKE) -C $(CF8385_DIR) clean

wifistix-dirclean:
	@echo Nothing to do to clean wifistix -- must be cleaned manually
	rm -rf $(CF8385_DIR)

#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_CF8385)),y)
TARGETS+=wifistix
endif
